# 采集基本信息
import traceback
from .base import Base
from utils.response import BaseResponse
from utils.log import logger


class BasicMsg(Base):

    def collect(self, my_ssh, host):
        response = BaseResponse()

        try:
            u_name = my_ssh(host, 'uname').strip()
            version = my_ssh(host, 'cat /etc/issue').strip().split('\n')[0]
            response.data = {
                'u_name': u_name,
                'version': version,
            }
        except Exception as e:
            logger.error(traceback.format_exc())
            response.status = False
            response.error = traceback.format_exc()

        return response.dict
